﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace SpeechSynthesizer.Parsers
{
    public class FilesParser
    {
        #region Vars

        public List<string> _filesLst;

        //public static readonly string directory = @"d:\Projects\C#\speech-synthesizer\ speech-synthesizer\SpeechSynthesizer\base\";
        public static readonly string directory = Directory.GetCurrentDirectory()+"\\base\\";

        #endregion

        #region Constructor

        public FilesParser(List<string> syllables)
        {
            Syllables = syllables;
        }

        public FilesParser()
        {
            _filesLst = new List<string>();
        }

        #endregion

        #region Properties

        public List<string> Files { get { return _filesLst; } }
        public List<string> Syllables { get; set; }

        #endregion

        #region Public Methods

        public void Parse()
        {
            List<string> allFiles = new List<string>();
            foreach (string syllable in Syllables)
            {
                //string path = Directory.GetCurrentDirectory();
                //rework directory, when release last version
                string path = directory + syllable + ".wav";
                FileInfo fileInfo = new FileInfo(path);                
                if(fileInfo.Exists)
                {
                    allFiles.Add(path);
                }
                else
                {
                    string path1, path2;
                    if(syllable.Length==3)
                    {
                        path1 = directory + syllable[0] + "'" + ".wav";
                        path2 = directory + syllable[2] + ".wav";
                    }
                    else
                    {
                        path1 = directory + syllable[0] + ".wav";
                        path2 = directory + syllable[1] + ".wav";
                    }
                    allFiles.Add(path1);
                    allFiles.Add(path2);
                }
            }
            _filesLst = allFiles;
        }

        #endregion
    }
}
